using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using EntLibEC.Cmn;
using EntLibEC.Biz;
using EntLibEC.Biz.Basic;

namespace EntLibEC.View.Init
{
	/// <summary>
	/// Summary description for ShipPriceTest.
	/// </summary>
	public partial class ShipPriceTest : PageBase
	{
	
		protected void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
			if(!IsPostBack)
				InitPage();
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    

		}
		#endregion

		private void InitPage()
		{
			this.ucArea.BindArea();
			this.ucShipType.BindShipType(true);
		}

		protected void btnCalc_Click(object sender, System.EventArgs e)
		{
			if(txtWeight.Text.Trim()==string.Empty||!Util.IsWholeNumber(txtWeight.Text.Trim())||int.Parse(txtWeight.Text.Trim())<0)
			{
				Assert(lblmsg,"Input weight error",-1);
				return;
			}
			else if(txtSOAmt.Text.Trim()==string.Empty||!Util.IsNumber(txtSOAmt.Text.Trim())||int.Parse(txtSOAmt.Text.Trim())<0)
			{
				Assert(lblmsg,"Input soamt error",-1);
				return;
			}
			else if(ucArea.AreaSysNo==AppConst.IntNull)
			{
				Assert(lblmsg,"Pls select an area",-1);
				return;
			}
			else if(ucShipType.ShipTypeSysNo==AppConst.IntNull)
			{
				Assert(lblmsg,"Pls select an shiptype",-1);
				return;
			}
			try
			{
				decimal shipPrice = 0;//ASPManager.GetInstance().GetShipPrice(int.Parse(txtWeight.Text.Trim()),decimal.Parse(txtSOAmt.Text.Trim()),ucShipType.ShipTypeSysNo,ucArea.AreaSysNo,);
				txtShipPrice.Text = shipPrice.ToString(AppConst.DecimalFormat);
				Assert(lblmsg,"Calc OK",1);
			}
			catch(BizException be)
			{
				txtShipPrice.Text = "0.00";
				Assert(lblmsg,be.Message,-1);
			}
			catch(Exception ex)
			{
				txtShipPrice.Text = "0.00";
				Assert(lblmsg,ex.Message,-1);
			}
		}

		protected void ucArea_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			this.ucShipType.BindShipTypeByArea(ucArea.AreaSysNo);
		}
	}
}
